home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994…tember: Reference Library / Dev.CD Sep 94.toast / Periodicals / develop / develop Issue 19 / develop 19 code / SimpliFace_V2 / Sources / Application.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-15  |  4.3 KB  |  147 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Application.h
  3.  
  4.     Contains:    TApplication interface
  5.  
  6.     This module derived from the Apple Shared Library Manager
  7.     sample source code supplied with ASLM 1.1 (note that ASLM
  8.     is NOT required for, or used in, this project).
  9.  
  10.     Developed by:
  11.  
  12.     Paul G Smith (commstalk hq & Full Moon Software, Inc)
  13.  
  14.     you can leave messages at (UK): 0727 844232; (US): 408 253 7199
  15.     BUT I prefer to be contacted by e-mail
  16.     AppleLink:     COMMSTALK.HQ
  17.     Internet:     COMMSTALK.HQ@applelink.apple.com
  18.  
  19.     "SimpliFace2" Sample code to accompany develop article
  20.     on techniques for controlling script inheritance.
  21.     
  22.     
  23.  
  24.  
  25. */
  26.  
  27. #ifndef __APPLICATION__
  28. #define __APPLICATION__
  29.  
  30. #ifndef __DESK__
  31. #include <Desk.h>
  32. #endif
  33.  
  34. #ifndef __OSUTILS__
  35. #include <OSUtils.h>
  36. #endif
  37.  
  38. #ifndef __APPLEEVENTS__
  39. #include <AppleEvents.h>
  40. #endif
  41.  
  42. #ifndef __SCRIPTOBJECTS__
  43. #include "ScriptableObjects.h"
  44. #endif
  45.  
  46.  
  47. /* this is a type declartion for the qd global so we can access its Labels */
  48. /* given a pointer to qd.  For some reason quickdraw doesn't define this type. */
  49. struct qdRec {
  50.     char privates[76];
  51.     long randSeed;
  52.     BitMap screenBits;
  53.     Cursor arrow;
  54.     Pattern dkGray;
  55.     Pattern ltGray;
  56.     Pattern gray;
  57.     Pattern black;
  58.     Pattern white;
  59.     GrafPtr thePort;
  60. };
  61.  
  62. /*
  63.     TApplication:
  64.  
  65.     This is our class which implements a basic Macintosh style program,
  66.     including a MultiFinder-aware event loop. 
  67. */
  68.  
  69. class TApplication : public TScriptableObject
  70. {
  71. public:
  72.     // Our constructor & destructor
  73.     TApplication(Ptr qdPtr);
  74.     TApplication();
  75.     virtual ~TApplication();
  76.  
  77.     // Call this routine to start event loop running
  78.     virtual    void EventLoop();
  79.  
  80.     // Call this routine to run event loop once
  81.     virtual    void InEventLoop();
  82.  
  83. protected:
  84.     // Returns total stack space required in bytes.
  85.     // Returns 0 by default, which tells the initialization code
  86.     // to use the default stack size.
  87.     virtual long StackNeeded();
  88.     // Returns total heap space required in bytes.
  89.     // Returns 0 by default, which tells the initialization code
  90.     // to use whatever heap size is given.
  91.     virtual long HeapNeeded();
  92.  
  93.     static    void AlertUser(short errResID, short errCode);
  94.     static    void BigBadError(short errResID, short errCode);
  95.  
  96.     // Loop control methods you may need to override
  97.     virtual void SetUp();                    // Run before event loop starts
  98.     virtual void CleanUp();                    // run at end of loop
  99.     virtual void ExitLoop();                // to end loop, call this routine
  100.     virtual void DoIdle();                    // idle time handler (blink caret, background tasks)
  101.     virtual void AdjustMenus();                // menu updater routine
  102.     
  103.     virtual Boolean     HandleEvent (EventRecord& theEvent, Boolean& pass);
  104.     // returns true if event was handled
  105.  
  106.     // event handlers you shouldn't need to override in a typical application
  107.     virtual void DoKeyDown();                // also called for autokey events
  108.     virtual void DoActivateEvt();            // handles setup, and calls DoActivate (below)
  109.     virtual void DoUpdateEvt();                // handles setup, and calls DoUpdate (below)
  110.     virtual void DoHighLevelEvent();        // handles Apple Events
  111.     virtual void DoOSEvent();                // Calls DoSuspend, DoResume and DoIdle as apropos
  112.     virtual void DoMouseDown();                // Calls DoContent, DoGrow, DoZoom, etc
  113.     virtual void DoMouseInSysWindow();
  114.     virtual void DoDrag();
  115.     virtual void DoGoAway();                // handles setup, calls TDocument::DoClose
  116.  
  117.     // called by EventLoop and its handlers:
  118.     virtual void AdjustCursor();        // cursor adjust routine, should setup mouseRgn
  119.     virtual void DoMenuCommand(short menuID, short menuItem);
  120.     // called by OSEvent (just calls DoActivate by default, so no clip conversion
  121.     // is done). If you want to convert clipboard, override these routines
  122.     virtual void DoSuspend(Boolean doClipConvert);
  123.     virtual void DoResume(Boolean doClipConvert);
  124.     
  125.     // If you have an app that needs to know about these, override them
  126.     virtual void DoMouseUp();
  127.     virtual void DoDiskEvt();
  128.  
  129.     // Utility routines you need to provide to do MultiFinder stuff
  130.     virtual unsigned long SleepVal();        // how long to sleep in WaitNextEvent
  131.  
  132. private:
  133.     virtual void        InitApplication(Ptr qdPtr);
  134.  
  135. protected:
  136.     // useful variables
  137.     Boolean            fDone;                    // set to true when we are ready to quit
  138.     EventRecord        fTheEvent;                // our event record
  139.     WindowPtr        fWhichWindow;            // currently active window
  140.     Boolean            fInBackground;            // true if our app is suspended
  141.     Boolean            fWantFrontClicks;        // true if we want front clicks
  142.     RgnHandle        fMouseRgn;                // mouse moved region (set it in your DoIdle)
  143.     qdRec*            fqd;                    // pointer to our qd globals
  144. };
  145.  
  146. #endif
  147.